<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="stylesheet" type="text/css" href="css/default.css" />
<script type="text/javascript">
	function validateForm(){
		String.prototype.trim = function () {
		    return this.replace(/^\s*/, "").replace(/\s*$/, "");
		};
		
		var txtTenSach = document['frmSearch'].bookName;	
		var cbFromPrice = document['frmSearch'].fromPrice;
		var cbToPrice = document['frmSearch'].toPrice;
		
		if (txtTenSach.value.trim() == ""){
			alert("Không được để trống tên sách.");
			txtTenSach.select();
			return false;
		}										
				
		var giaTu = parseInt(cbFromPrice.options[cbFromPrice.selectedIndex].text);
		var giaDen = parseInt(cbToPrice.options[cbFromPrice.selectedIndex].text);							
		
		if (giaTu > giaDen){
			alert("Giá từ phải nhỏ hơn giá đến.");
			return false;
		}
		
		return true;
	}
	
	function populateComboboxGia(combobox, min, max, seek){
		var combobox = document.getElementById(combobox);
		for(i = min; i <= max; i = i + seek){
			var item = document.createElement('option');
			item.text = i.toString();
			
			try{
				combobox.add(item,null); // standards compliant
			}
			catch(ex)
			  {
				combobox.add(item); // IE only
			  }
		}
	
	}
	
</script>
<title>Search Book</title>
</head>
<body onload="populateComboboxGia('cbFromPrice', 50000, 400000, 50000);
	populateComboboxGia('cbToPrice', 50000, 400000, 50000);">
<%@ include file="header.html"%>
<%@ include file="leftside.html" %>
<div id="indexRightColumn" align="center">
<form action="productsBySearch.jsp" method="GET" name="frmSearch" onsubmit="return validateForm();">
<table>
	<tr>
		<td colspan="2" align="center"><strong>Search Book</strong></td>
	</tr>
	<tr>
		<td>Book name</td>
		<td><input type="text" name="bookName" /></td>
	</tr>
	<tr>
		<td>Price From</td>
		<td><select id="cbFromPrice" name="fromPrice"></select></td>
	</tr>
	<tr>
		<td>To</td>
		<td><select id="cbToPrice" name="toPrice" ></select></td>
	</tr>
	<tr>
		<td colspan="2">
			<input type="submit" value="Search"/> 
			<input type="reset" value="Reset" />
		</td>
	</tr>
</table>
</form>
</div>
<%@ include file="footer.html" %>
</body>
</html>